﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using App.Data;
using App.Core.Extensions;


public partial class Pages_Public_ArticleDetails : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = WebUtil.GetPageTitle(h4Heading.InnerHtml);
        if (!IsPostBack)
        {
            BindNewsDetails();
        }
    }

    protected void BindNewsDetails()
    {
        int id = WebUtil.GetQueryStringInInt(AppConstants.QueryString.ID);
        BtcHousingEntities context = new BtcHousingEntities();
        var news = context.Articles.FirstOrDefault(A => A.ID == id);
        if (news == null)
        {
            pnlFormContainer.Visible = false;
            WebUtil.ShowMessageBox(divMessage, "Sorry! Requested Article was not found", true);
        }
        else
        {
            h4Heading.InnerHtml = news.Title.HtmlEncode();
            Page.Title = WebUtil.GetPageTitle(h4Heading.InnerHtml);
            ltrPublishedOn.Text = news.PublishedOn.ToString(AppConstants.ValueOf.DATE_FROMAT_DISPLAY);
            String newsPhoto = "<img src='" + AppConstants.ARTICLE_FILES + "/{0}' alt='' title='' align='right' class='NewsPhoto' />";
            StringBuilder sb = new StringBuilder();
            if (!news.Image1.IsNullOrEmpty())
                sb.AppendFormat(newsPhoto, news.Image1);
            sb.Append(WebUtil.FormatText(news.ArticleContent));
            ltrNewsDetails.Text = sb.ToString();
        }
    }
}